﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WPF入门
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            // 所有界面上的控件都在这个方法中
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            listBox1.Items.Add("yejing");
            Dictionary<int, string> dict = new Dictionary<int, string>();
            dict.Add(1, "yejing");
            
            comboBox1.Items.Add(dict[1]);

            FormContext._form1 = this;
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var item = listBox1.SelectedItem;
            //MessageBox.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add("item"+listBox1.Items.Count);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            checkedListBox1.Items.AddRange(new string[] { "a","b","b"});
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("hello world");
            Form2 form2 = new Form2();
            form2.Show();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            string chs = textBox1.Text;
            string ucode = String2Unicode(chs);
            textBox2.Text = ucode;
        }


        public string String2Unicode(string source)
        {
            byte[] bytes = Encoding.Unicode.GetBytes(source);
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < bytes.Length; i += 2)
            {
                stringBuilder.AppendFormat("\\u{0}{1}", bytes[i + 1].ToString("x").PadLeft(2, '0'), bytes[i].ToString("x").PadLeft(2, '0'));
            }
            return stringBuilder.ToString();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            string str = textBox2.Text;
            if(str != null && str.Length >0)
            {
                textBox2.Copy();
            }
        }
    }
}
